<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>创建移动应用基本信息</title>
<%@ include file="/adapter/adapter-bootstrap.jsp" %>


<script type="text/javascript">
var tempid="";
     function vailId()
            {
               tempid=document.getElementById("appId").value;
               tempid=tempid.replace(/(^\s*)|(\s*$)/g, ""); 
              if(tempid == null || tempid== undefined || tempid == '')
              {
                 alert("移动应用标识不能为空");
                 return;
              }
              if(escape(tempid).indexOf("%u")>0)
              {
            	  alert("移动应用标识不能包含特殊字符");
            	  document.getElementById("appId").value="";
      	        document.getElementById("appId").focus();
             } else{
            	  ajaxRequest();
              }    	         
	         
            }
     function ajaxRequest() {
    	    $.ajax({
    	      url: "${pageContext.request.contextPath }/appBaseInfo/findid?appid='"+tempid+"'",
    	      type: "POST",
    	      dataType: "json",
    	      async: false,
    	      success: function(data) {  
        	      var jspstate=data.model.idflag;
        	      if(jspstate==9999){
        	    	  alert("系统异常请联系管理员");
            	      }
        	      if(jspstate!=0 && jspstate!=9999){
        	    	    alert("移动应用标识已存在");
          	           document.getElementById("appId").value="";
          	            document.getElementById("appId").focus();
            	      }  
    	      },
    	      error: function() {    	        
    	        alert("error");
    	      }
    	    });
    	  }
     function save(){
          if(checkData()){
        	  $.ajax({
        			type:'post',
        			url:'${pageContext.request.contextPath }/appBaseInfo/addAppBaseInfo',
        		    dataType: "json",
        		    data:$("#baseinfo").serialize(),
        		    async: false,
        			success:function(data){//返回json结果
            			var addstate=data.model.addflag;
            			if(data.model.ec==0){
            				alert(addstate);
            			}else{
            				alert("新增应用成功!");
            				//window.location.href="${pageContext.request.contextPath }/appBaseInfo/queryList";
            				try{
            					opener.document.location.reload(true);
            				} catch(e){

                			}
            				window.close();
                		}
        			}
        		});
          }
     }
     
     function changurl(obj){
    	 tempid=document.getElementById("appId").value;
         tempid=tempid.replace(/(^\s*)|(\s*$)/g, ""); 
        if(tempid == null || tempid== undefined || tempid == '')
        {
           alert("移动应用标识不能为空");
           obj.checked = false; 
           return;
        }
        if(obj.value=='1'){
        	document.getElementById("projectUrl").style.display="block";
        	document.getElementById("appProjectUrl").value='${svnUrl}/'+tempid;
        }else{
        	document.getElementById("projectUrl").style.display="none";
        	document.getElementById("appProjectUrl").value="";
        }
        
     }
     
     function checkData(){
    	 if(tempid == null || tempid== undefined || tempid == ''){
       	  	  alert("移动应用标识不能为空");
	          document.getElementById("appId").value="";
	          document.getElementById("appId").focus();
	          return false;
          }
    	  var radios = document.getElementsByName('isMake');   
 		  var flag = false;   
 		  for(var i=0;i<radios.length;i++){  
 		     if(radios[i].checked){   
 				flag = true;   
 				break;   
 			 }   
 		  }   
 		  if(flag == false){   
 			 alert('请选择单选按钮');   
 			 return false;   
 		  }
    	  return true;
     }

</script>
</head>
<body>
<div class="panel panel-default ">
   <div class="panel-heading">
      <h3 class="panel-title">
          创建应用
      </h3>
   </div>
   <div class="panel-body">
	<form class="form-horizontal" role="form" id="baseinfo" name="baseinfo"  action="${pageContext.request.contextPath }/appBaseInfo/addAppBaseInfo" method="post">
                    <fieldset>
                       <div class="form-group">
                          <label class="col-xs-2 control-label" for="ds_host">移动应用标识</label>
                          <div class="col-xs-4">
                             <input class="form-control" id="appId" name="appId" type="text"  onBlur="vailId()"/> 
                          </div>
                          <label class="col-xs-2 control-label" for="ds_name">移动应用名称</label>
                          <div class="col-xs-4">
                             <input class="form-control" id="appName" name="appName" type="text" />
                          </div>
                       </div>
                       <div class="form-group">
                          <label class="col-xs-2 control-label" for="ds_username">当前版本号</label>
                          <div class="col-xs-4">
                             <input class="form-control" id="appVersionId" name="appVersionId" type="text" />
                          </div>
                          <label class="col-xs-2 control-label" for="ds_password">发布版本日期</label>
                          <div class="col-xs-4">
                             <input class="form-control" id="appVersionDate" name="appVersionDate" type="text" class="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"/>
                          </div>
                       </div>
                       <div class="form-group">
                          <label class="col-xs-2 control-label" for="ds_username">移动应用状态</label>
                          <div class="col-xs-4">
                              <select id="s_appState" name="s_appState" class="form-control" disabled="disabled">
                              <option value="1">正常</option>
                               <option value="2">下线</option>
                              </select>
                             
                             <input class="form-control" id="appState" name="appState" type="hidden" value="1"/>
                          </div>
                          <label class="col-xs-2 control-label" for="ds_username">应用类型</label>
                          <div class="col-xs-4">
                              <select id="appType" name="appType" class="form-control">
                              <option value="10" selected="selected">手机</option>
                               <option value="20">平板</option>
                              </select>
                            <!--  <input class="form-control" id="appState" name="appState" type="text" /> -->
                          </div>
                       </div>
                       <div class="form-group" id="projectUrl" style="display: none;">
                          <label class="col-xs-2 control-label">应用工程地址</label>
                          <div class="col-xs-10">
 							  <input class="form-control" id="appProjectUrl" name="appProjectUrl" type="text"/>
                          </div>
                       </div>
                       <div class="form-group">
                          <label class="col-xs-2 control-label" for="ds_password">备注</label>
                          <div class="col-xs-10">
                             <textarea class="form-control" rows="3" id="remarks" name="remarks" >
                             </textarea>
                          </div>
                       </div>
                       <div class="form-group">
                          <label class="col-xs-2 control-label"><input type="radio" id="isMake" name="isMake" value="0" onclick="changurl(this)"/></label>
                          <div class="col-xs-4">
                             <label >
                             	创建应用时，在SVN中创建基础工程
                          	</label>
                          </div>
                          <label class="col-xs-2 control-label"><input type="radio" id="isMake" name="isMake" value="1" onclick="changurl(this)"/></label>
                          <div class="col-xs-4">
                             <label >SVN中已存在工程，创建时不再生成基础工程</label>
                          </div>
                       </div>
                    </fieldset>     
                </form>
	</div>
	</div>
                    <br></br>

					<div class="form-group">
						<div class="col-xs-5"></div>
						<div class="col-xs-5">
							<button type="button" class="btn btn-default" onclick="save()">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>
							<button type="button" class="btn btn-default"  onclick="window.close()">&nbsp;&nbsp;关闭&nbsp;&nbsp;</button>
						</div>
					</div>
                    <br></br>	
</body>
</html>
